<?php include_once ('function/check_login_function.php'); ?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Health Tracker</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Health Tracker">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <style>
      body {
        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
      }
    </style>
    <link href="css/bootstrap-responsive.css" rel="stylesheet">
    <link rel="shortcut icon" href="ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="ico/apple-touch-icon-57-precomposed.png">
  </head>

  <body>


<?php include_once('nav.php'); ?>
    <div class="container">
    <div class="row">
    <div class="span5">
      <h1 style="padding-left: 20px;">Your profile</h1>
			<?php 
			
	  			if (isset($_SESSION['message'])) {
					foreach ($_SESSION['message'] as $message) {
						echo '<div class="alert">'.constant($message) . '</div>';
					}
					unset($_SESSION['message']);
				} 

				if ($user->getRole() === 'doctor') {
					if (intval($user->getVerified()) === intval(false)) {
						echo '<p class="text-error">' . constant("ERROR_DOCTOR_UNVERIFIED") . '</p>';
					}
				}
				
				if (!$user->isValid()) { ?>	
					<p class="text-error"><?php echo constant("ERROR_ACCOUNT_INVALID")?></p>
					<form action="function/form_function.php" method="POST" >
					<label for="token">Token: </label> <input type="text" class="input-small" id="token" name="token" style="margin-top:8px;"/>
					<input type="hidden" id="from" name="from" value="profile"/>
                    <button type="submit" name="validateAccount" class="btn btn-primary">Validate</button>
                    <button type="submit" name="resendToken" class="btn btn-primary">Resend Token</button>
					</form>
				<?php } ?>
				<?php

                echo '<table class="table table-striped" style="margin-left:20px;">';		
				echo '<tr><th colspan="2">Details</th></tr>';
				echo "<tr><td>Username:</td><td>". $user->getUsername() . "</td></tr>";
				echo "<tr><td>E-mail:</td><td>". $user->getEmail() . "</td></tr>";
				echo "<tr><td>Name:</td><td>". $user->getFirstname().' '.$user->getLastname()."</td></tr>";
				echo "<tr><td>Gender:</td><td>". $user->getGender() . "</td></tr>";

					$address = explode('|', $user->getAddress());
					$address1 = $address[0];
					$address2 = $address[1];
					$city = $address[2];
					$state = $address[3];
					$country = $address[4];
					$postal = $address[5];

					$display_address = "";
					if (strlen($address1) + strlen($address2) !== 0) {
						$display_address .= $address1 . ' '. $address2 . '<br />';
					}
					if (strlen($city) + strlen($state) !== 0) {
						$display_address .= $city . ' '. $state . '<br />';
					}
					if (strlen($country) + strlen($postal) !== 0) {
						$display_address .= $country . ' '. $postal . '<br />';
					}					
				echo "<tr><td>Address:</td><td>". $display_address  . "</td></tr>";
				echo "<tr><td>Contact:</td><td>". $user->getContact()  . "</td></tr>";
				echo "<tr><td>Date of Birth:</td><td>". $user->getDoB()  . "</td></tr>";
				echo "</table>";
				
				if ($user->getRole() === 'doctor') {
					echo "Registration no.: " . $user->getRegNo() . "<br />";
					echo "Speciality: " . $user->getSpeciality() . "<br />";
					$hospital_list = $user->getHospitalList();
					if ($hospital_list !== null) {
						foreach ($hospital_list as $hospital) {
							echo 'Hospital: ' . $hospital['hospital_name'] . "<br />";
						}
					} 
				}
				if ($user->getRole() === 'patient') {
					echo "Bloodtype: " . $user->getBloodtype() . "<br />";
					echo "Allergy: " . $user->getAllergy() . "<br />";
				}
				?>
    </div>
    <?php
                echo '<div class="span3" style="padding-left:20px">';
				include_once('notifications_box.php');
                echo '</div>';	
    ?>
    </div>
    </div> <!-- /container -->
  </body>
</html>